<?php
session_start();
include_once 'conn.php';
$mainID = $_POST['mainID'];
$quoteID = $_POST['replyID'];
$contents = $_POST['contents'];
if($quoteID){
    $sql = "insert into subtopic (maintopicid, userid, quoteid, posttime, contents) values ('$mainID','".$_SESSION['userID']."','$quoteID','".date("Y-m-d H:i:s")."','$contents')";
}
else{
    $sql = "insert into subtopic (maintopicid, userid,  posttime, contents) values ('$mainID','".$_SESSION['userID']."','".date("Y-m-d H:i:s")."','$contents')";
}
$result = mysqli_query($conn,$sql);
if($result){
    $a['error'] = 0;
}
else{
    $a['error'] = 1;
    $a['sql'] = $sql;
    $a['errMsg'] = mysqli_error($conn);
}
echo json_encode($a);